package com.yytek.am.controller;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yytek.common.log.annotation.Log;
import com.yytek.common.log.enums.BusinessType;
import com.yytek.common.security.annotation.RequiresPermissions;
import com.yytek.am.domain.FmEventRecord;
import com.yytek.am.service.IFmEventRecordService;
import com.yytek.common.core.web.controller.BaseController;
import com.yytek.common.core.web.domain.AjaxResult;
import com.yytek.common.core.utils.poi.ExcelUtil;
import com.yytek.common.core.web.page.TableDataInfo;

/**
 * 告警原始事件Controller
 * 
 * @author yytek-iot
 * @date 2022-10-10
 */
@Api(value = "告警原始事件控制器", tags = {"告警原始事件管理"})
@RestController
@RequestMapping("/record")
public class FmEventRecordController extends BaseController
{
    @Autowired
    private IFmEventRecordService fmEventRecordService;

    /**
     * 查询告警原始事件列表
     */
    @ApiOperation("查询告警原始事件列表")
    @RequiresPermissions("am:record:list")
    @GetMapping("/list")
    public TableDataInfo list(FmEventRecord fmEventRecord)
    {
        startPage();
        List<FmEventRecord> list = fmEventRecordService.selectFmEventRecordList(fmEventRecord);
        return getDataTable(list);
    }

    /**
     * 导出告警原始事件列表
     */
    @ApiOperation("导出告警原始事件列表")
    @RequiresPermissions("am:record:export")
    @Log(title = "告警原始事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmEventRecord fmEventRecord)
    {
        List<FmEventRecord> list = fmEventRecordService.selectFmEventRecordList(fmEventRecord);
        ExcelUtil<FmEventRecord> util = new ExcelUtil<FmEventRecord>(FmEventRecord.class);
        util.exportExcel(response, list, "告警原始事件数据");
    }

    /**
     * 获取告警原始事件详细信息
     */
    @ApiOperation("获取告警原始事件详细信息")
    @RequiresPermissions("am:record:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fmEventRecordService.selectFmEventRecordById(id));
    }

    /**
     * 新增告警原始事件
     */
    @ApiOperation("新增告警原始事件")
    @RequiresPermissions("am:record:add")
    @Log(title = "告警原始事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmEventRecord fmEventRecord)
    {
        return toAjax(fmEventRecordService.insertFmEventRecord(fmEventRecord));
    }

    /**
     * 修改告警原始事件
     */
    @ApiOperation("修改告警原始事件")
    @RequiresPermissions("am:record:edit")
    @Log(title = "告警原始事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmEventRecord fmEventRecord)
    {
        return toAjax(fmEventRecordService.updateFmEventRecord(fmEventRecord));
    }

    /**
     * 删除告警原始事件
     */
    @ApiOperation("删除告警原始事件")
    @RequiresPermissions("am:record:remove")
    @Log(title = "告警原始事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fmEventRecordService.deleteFmEventRecordByIds(ids));
    }
}
